package com.hoshiibuy.company.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hoshiibuy.common.rpc.Response;
import com.hoshiibuy.company.service.IOrganizationTypeService;
import com.hoshiibuy.company.entity.AttachmentType;
import com.hoshiibuy.company.entity.OrganizationType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 机构类型 前端控制器
 * </p>
 *
 * @author WGJ
 * @since 2019-04-22
 */
@RestController
@RequestMapping("/orgtype")
@Api(value = "机构类型管理", tags = {"机构类型操作接口"})
public class OrganizationTypeController {
    @Autowired
    private IOrganizationTypeService orgTypeService;

    /**
     * @param id
     * @return com.hoshiibuy.common.rpc.Response
     * @description: 根据id查询附件信息
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "查询",
            notes = "查询机构类型信息",
            produces = "application/json, application/xml",
            consumes = "application/json, application/xml")
    public Response findOrgtypeById(Long id) {

        return Response.data(orgTypeService.getById(id));
    }

    /**
     * @param
     * @return com.hoshiibuy.common.rpc.Response
     * @description: 根据名称查询
     */
    @GetMapping("/find/{name}")
    @ApiOperation(value = "查询",
            notes = "根据查询机构类型信息",
            produces = "application/json, application/xml",
            consumes = "application/json, application/xml")
    public Response findOrgtypeByName(String name) {

        Wrapper wrapper = Wrappers.<AttachmentType>query().lambda().eq(AttachmentType::getName, name);

        return Response.data(orgTypeService.getOne(wrapper));

    }

    /**
     * @param organizationType
     * @return com.hoshiibuy.common.rpc.Response
     * @description: 新增
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增",
            notes = "新增机构类型信息",
            produces = "application/json, application/xml",
            consumes = "application/json, application/xml")
    public Response saveOrgtype(@Valid OrganizationType organizationType) {

        return Response.data(orgTypeService.save(organizationType));
    }

    /**
     * @param organizationType
     * @return com.hoshiibuy.common.rpc.Response
     * @description: 修改
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改",
            notes = "修改机构类型信息",
            produces = "application/json, application/xml",
            consumes = "application/json, application/xml")
    public Response updateOrgtypeById(@Valid OrganizationType organizationType) {
        return Response.data(orgTypeService.updateById(organizationType));

    }
}
